<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:doc="livcos.org/ns/doc"
  xmlns:pm="livcos.org/ns/pm"
  xmlns:um="livcos.org/ns/mgt/user"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:f="livcos.org/ns/xslt/function"
  xmlns:v="livcos.org/ns/view"
  exclude-result-prefixes="doc pm um f v">
	
	<xsl:import href="news.xsl"/>
	<xsl:import href="usecase.xsl"/>
	
	<xsl:template match="pm:task">
		<xsl:variable name="p" select="if (@priority) then @priority else 3"/>
		<xsl:variable name="progress"
			select="if (not(@progress) and (@effort > 0)) then (@effort div @estimate) * 100 else @progress"/>
		<div id="{@id}" class="task task_p{$p}">
			<xsl:attribute name="class">
				<xsl:text>task task_p</xsl:text>
				<xsl:value-of select="$p"/>
				<xsl:if test="$progress &gt;= 100">_completed</xsl:if>
			</xsl:attribute>
			<v:style ref="{resolve-uri('styles.css')}"/>
			<xsl:choose>
				<xsl:when test="$progress &gt;= 100">
					<div class="label">TASK:</div>
				</xsl:when>
				<xsl:otherwise>
					<div class="label task_p{$p}_label">
						<xsl:value-of select="if ($p = 1) then 'TODO!' else 'TODO:'"/>
					</div>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:if test="$progress">
				<div class="progress_box">
					<xsl:if test="$progress &gt; 0">
						<div class="progress_bar" style="width:{$progress}%">
							<xsl:text>&#160;</xsl:text>
						</div>
					</xsl:if>
				</div>
			</xsl:if>
			<p><xsl:value-of select="pm:title"/></p>
			<xsl:apply-templates select="pm:description | doc:*"/>
			<xsl:if test="pm:depends">
				<p style="font-size: 80%; margin-left: 2em">Depends on <xsl:apply-templates select="pm:depends"/>.</p>
			</xsl:if>
			<xsl:if test="pm:source">
				<p style="font-size: 80%; margin-left: 2em">Sources: <xsl:apply-templates select="pm:source"/>.</p>
			</xsl:if>
		</div>
	</xsl:template>

	<xsl:template match="pm:description">
		<p>
			<xsl:apply-templates select="node()"/>
		</p>
	</xsl:template>
	
	<xsl:template match="pm:depends">
		<xsl:if test="position() > 1">, </xsl:if>
		<span id="{@id}">
			<xsl:if test="doc:*">
				<xsl:attribute name="title" select="doc:*[1]"/>
			</xsl:if>
			<xsl:choose>
				<xsl:when test="not(@on) or (@on = '') or (@on = '#')">-- task --</xsl:when>
				<xsl:otherwise>
					<xsl:apply-templates select="f:entity(@on, .)" mode="list"/>
				</xsl:otherwise>
			</xsl:choose>
		</span>
	</xsl:template>
	
	<xsl:template match="pm:source">
		<xsl:if test="position() > 1">, </xsl:if>
		<span id="{@id}">
			<xsl:if test="doc:*">
				<xsl:attribute name="title" select="doc:*[1]"/>
			</xsl:if>
			<xsl:choose>
				<xsl:when test="not(@ref) or (@ref = '') or (@ref = '#')">-- source --</xsl:when>
				<xsl:otherwise>
					<xsl:apply-templates select="f:entity(@ref, .)" mode="list"/>
				</xsl:otherwise>
			</xsl:choose>
		</span>
	</xsl:template>
	
	<xsl:template match="pm:task" mode="list">
		<a href="#{@id}">
			<xsl:value-of select="pm:title"/>
		</a>
	</xsl:template>
	
	<xsl:template match="um:person" mode="list">
		<a href="{f:caller-uri('/livcos.org/web/User.view')}?login={@id}">
			<xsl:value-of select="um:name"/>
			<xsl:text> </xsl:text>
			<xsl:value-of select="um:first-name"/>
		</a>
	</xsl:template>
	
</xsl:stylesheet>
